<template>
  <div class="qyui-cell bdr" style="width:150px">
    <el-tree
      ref="tree"
      node-key="id"
      :data="showTree"
      highlight-current
      default-expand-all :expand-on-click-node="false"
      @node-contextmenu="handleContextmenu"
    >

    </el-tree>
  </div>
</template>
<script>

export default {
  inject: ['manager'],
  data() {
    return {
      event: null,
      menuOpen: false,
      menus: [

      ],
    };
  },
  computed: {
    showTree() {
      const tree = [];
      if (this.manager.Body.AllGridViews.length > 0) {
        this.manager.Body.AllGridViews.forEach(a => {
          const table = { id: 'table_' + a.ID, label: a.Name, type: 'table', children: [] };
          a.Rows.forEach(row => {
            table.children.push({
              id: 'row_' + row.ID,
              label: row.Type + '_' + row.RowIndex,
              type: 'row',
            });
          });
          tree.push(table);
        });
      }
      return tree;
    },
  },
  watch: {
    'manager.states.tableIndex': {
      handler(val) {
        // 设置当前行
        if (val > -1) {
          const id = this.manager.Body.AllGridViews[val].ID;
          this.$nextTick(() => {
            this.$refs.tree.setCurrentKey('table_' + id);
          });
        }
      },
    },
  },
  methods: {

    menuClick() {
    },
  },
};
</script>
<style >

</style>
